<html>
<head><meta charset="utf-8"><title>macro injection tests · edition 2021 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/index.html">edition 2021</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html">macro injection tests</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="243488305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243488305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243488305">(Jun 22 2021 at 08:56)</a>:</h4>
<p>My hunch is that most of the edition-dependent features don't have a documented bit of text that we use to figure out what edition they are-- and that we don't have tests for that logic. I think we should file an issue to clarify this and document the "edition span" in the Edition Migration Guide.</p>



<a name="243488524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243488524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243488524">(Jun 22 2021 at 08:58)</a>:</h4>
<p>(Also, I wish we used our repo more!)</p>



<a name="243488597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243488597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243488597">(Jun 22 2021 at 08:59)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/86539">https://github.com/rust-lang/rust/issues/86539</a></p>



<a name="243504739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243504739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243504739">(Jun 22 2021 at 11:55)</a>:</h4>
<blockquote>
<p>(Also, I wish we used our repo more!)</p>
</blockquote>
<p>What do you mean?</p>



<a name="243504939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243504939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243504939">(Jun 22 2021 at 11:57)</a>:</h4>
<blockquote>
<p>clarify this and document the "edition span"</p>
</blockquote>
<p>We should also decide in how much detail we want to document this and make guarantees. E.g. we can say 'the panic!(..) invocation', or we can clarify that's it specifically the <code>std</code> or <code>!</code> or <code>(</code> in <code>std::panic!(..)</code>. While in the end exactly one token is used, we might not want to make any guarantees more than just 'the span of <code>std::panic!</code>' or something like that.</p>



<a name="243505111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243505111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243505111">(Jun 22 2021 at 12:00)</a>:</h4>
<p>There's a few cases of <code>span_a.with_lo(span_b.lo())</code> to merge spans. (E.g. to merge <code>$</code> with <code>x</code> in <code>$x</code>.) This will keep the edition of span_a, not span_b. But i doubt that was really a choice made on purpose. (Instead of <code>span_b.with_hi(span_a.hi())</code>, which is equivalent if span_a and span_b have the same metadata, which is almost always the case.)</p>



<a name="243526472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243526472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243526472">(Jun 22 2021 at 14:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="310399">Mara</span> <a href="#narrow/stream/268952-edition-2021/topic/macro.20injection.20tests/near/243504739">said</a>:</p>
<blockquote>
<p>What do you mean?</p>
</blockquote>
<p>I just like filing issues on a space dedicated to a particular project, versus the rust-lang/rust repo, which has that "black hole" feeling to me</p>



<a name="243526640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243526640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243526640">(Jun 22 2021 at 14:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="310399">Mara</span> <a href="#narrow/stream/268952-edition-2021/topic/macro.20injection.20tests/near/243504939">said</a>:</p>
<blockquote>
<p>We should also decide in how much detail we want to document this and make guarantees. E.g. we can say 'the panic!(..) invocation', or we can clarify that's it specifically the <code>std</code> or <code>!</code> or <code>(</code> in <code>std::panic!(..)</code>. While in the end exactly one token is used, we might not want to make any guarantees more than just 'the span of <code>std::panic!</code>' or something like that.</p>
</blockquote>
<p>Yes, I believe we want to document this in very precise detail. =)  There's no reason to be loosey-goosey about it. There was an open issue around it, I'm somewhat of the opinion that it makes sense to tie those spans to a particular token in each case, as it's easy to explain.</p>



<a name="243526681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243526681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243526681">(Jun 22 2021 at 14:41)</a>:</h4>
<p>It's basically a "lang team call", I thnk, but it needs someone to draw up a proposal</p>



<a name="243526705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243526705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243526705">(Jun 22 2021 at 14:41)</a>:</h4>
<p>And yes, it's exactly those kind of "merging" cases that I am worried about and why I want to see some tests</p>



<a name="243534164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243534164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243534164">(Jun 22 2021 at 15:30)</a>:</h4>
<p>I do think we should be consistent across various span-dependent edition-dependent cases. I personally think we should use the span of the function/macro name whenever possible.</p>



<a name="243540131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243540131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243540131">(Jun 22 2021 at 16:13)</a>:</h4>
<blockquote>
<p>the span of the function/macro name whenever possible.</p>
</blockquote>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">panic</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">a</span><span class="p">;</span><span class="w"></span>
<span class="k">crate</span>::<span class="n">a</span><span class="o">!</span><span class="p">(</span><span class="s">".."</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>So which span should it use here?</p>



<a name="243540422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243540422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243540422">(Jun 22 2021 at 16:15)</a>:</h4>
<blockquote>
<p>There's no reason to be loosey-goosey about it.</p>
</blockquote>
<p>The decisions on how to merge spans are mostly based on what gives nice diagnostics. Adding (maybe unnecssarily) strict requirements to them for the edition context might make it harder to keep giving nice  diagnostics.</p>



<a name="243540874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243540874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243540874">(Jun 22 2021 at 16:18)</a>:</h4>
<blockquote>
<p>I just like filing issues on a space dedicated to a particular project, versus the rust-lang/rust repo, which has that "black hole" feeling to me</p>
</blockquote>
<p>Interesting. For me, everything that's <em>not</em> rust-lang/rust is a "black hole". Searching through all issues of a single repository has much nicer tools than searching through the entire organisation. I can't easily keep track of which repositories exist and which issue might be attached to which one..</p>



<a name="243541475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243541475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243541475">(Jun 22 2021 at 16:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/268952-edition-2021/topic/macro.20injection.20tests/near/243526705">said</a>:</p>
<blockquote>
<p>And yes, it's exactly those kind of "merging" cases that I am worried about and why I want to see some tests</p>
</blockquote>
<p>there are many places in rustc where it is assumed that the first and last token in things like <code>::some::path</code> carry the exact same context. see also the FIXMEs in Span::to. So, also for things like hygiene: should that be based on <code>path</code> or on the first <code>::</code>? (Right now it is the first <code>::</code> if both or neither come from a macro, or the one that comes from the macro otherwise. Usually. I believe. At least until some FIXMEs are fixed. Maybe. ^^' Also, the tokens in the middle are completely ignored.)</p>



<a name="243541919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243541919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243541919">(Jun 22 2021 at 16:27)</a>:</h4>
<p>(And <code>Span::until</code> and <code>Span::between</code> have different behaviour than <code>Span::to</code>. Those pick whichever does <em>not</em> come from a macro instead.)</p>



<a name="243543391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243543391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243543391">(Jun 22 2021 at 16:37)</a>:</h4>
<p>To be honest, I think the answers to these questions are less important than having an answer</p>



<a name="243543522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243543522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243543522">(Jun 22 2021 at 16:38)</a>:</h4>
<p>i'm just worried about hacky code in the future trying to maintain compatibility with the current not-very-well-defined state</p>



<a name="243544281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243544281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243544281">(Jun 22 2021 at 16:44)</a>:</h4>
<p>Fun:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="c1">// library crate in Rust 2021:</span>
<span class="cp">#[macro_export]</span><span class="w"></span>
<span class="fm">macro_rules!</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">(</span><span class="cp">$t</span>:<span class="nc">tt</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="cp">$t</span>::<span class="fm">panic!</span><span class="p">(</span><span class="s">"{{"</span><span class="p">);</span><span class="w"> </span><span class="p">};</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="cp">#[macro_export]</span><span class="w"></span>
<span class="fm">macro_rules!</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">(</span><span class="cp">$t</span>:<span class="nc">tt</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">std</span>::<span class="cp">$t</span><span class="o">!</span><span class="p">(</span><span class="s">"{{"</span><span class="p">);</span><span class="w"> </span><span class="p">};</span><span class="w"> </span><span class="p">}</span><span class="w"></span>


<span class="c1">// binary crate in Rust 2018:</span>
<span class="k">use</span><span class="w"> </span><span class="n">dep2021</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>

<span class="fm">macro_rules!</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">x</span><span class="o">!</span><span class="p">(</span><span class="n">std</span><span class="p">);</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="w">    </span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">y</span><span class="o">!</span><span class="p">(</span><span class="n">panic</span><span class="p">);</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span><span class="o">!</span><span class="p">(</span><span class="n">std</span><span class="p">);</span><span class="w">   </span><span class="c1">// 2021</span>
<span class="w">    </span><span class="n">y</span><span class="o">!</span><span class="p">(</span><span class="n">panic</span><span class="p">);</span><span class="w"> </span><span class="c1">// 2021</span>
<span class="w">    </span><span class="n">z</span><span class="o">!</span><span class="p">(</span><span class="n">x</span><span class="p">);</span><span class="w">     </span><span class="c1">// 2018 !!</span>
<span class="w">    </span><span class="n">z</span><span class="o">!</span><span class="p">(</span><span class="n">y</span><span class="p">);</span><span class="w">     </span><span class="c1">// 2021</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="243544563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243544563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243544563">(Jun 22 2021 at 16:46)</a>:</h4>
<p>an <code>std::panic</code> path with <em>either</em> the <code>std</code> or <code>panic</code> token from a 2021 macro resolves to the 2021 panic, because <code>Span::to</code> prefers macros. but when both come from a macro, it just picks the first token instead.</p>



<a name="243544680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243544680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243544680">(Jun 22 2021 at 16:47)</a>:</h4>
<p>so if you just want to document the current behaviour, this is what we end up with <span aria-label="grimacing" class="emoji emoji-1f62c" role="img" title="grimacing">:grimacing:</span></p>



<a name="243544776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243544776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243544776">(Jun 22 2021 at 16:47)</a>:</h4>
<p>that's why i think it might be better to just say "the edition of the <code>std::panic</code> path", and leave it unspecified what we do if you do weird things like this.</p>



<a name="243545344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243545344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243545344">(Jun 22 2021 at 16:51)</a>:</h4>
<p>same for the hygiene of <code>$a::$b</code> or something. right now it follows the same 'whichever is from a macro and otherwise just the first' (// FIXME) logic.</p>



<a name="243545803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243545803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243545803">(Jun 22 2021 at 16:55)</a>:</h4>
<p>if it needs to be well defined in all cases, then Span::to/between/until shouldn't exist, and should always require explicitly picking a context. But what makes sense for editions and hygiene might be a bad choice for diagnostics.</p>



<a name="243548729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243548729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243548729">(Jun 22 2021 at 17:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="310399">Mara</span> <a href="#narrow/stream/268952-edition-2021/topic/macro.20injection.20tests/near/243540131">said</a>:</p>
<blockquote>
<blockquote>
<p>the span of the function/macro name whenever possible.</p>
</blockquote>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">panic</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">a</span><span class="p">;</span><span class="w"></span>
<span class="k">crate</span>::<span class="n">a</span><span class="o">!</span><span class="p">(</span><span class="s">".."</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>So which span should it use here?</p>
</blockquote>
<p>The span of the token <code>panic</code>.</p>



<a name="243549612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243549612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243549612">(Jun 22 2021 at 17:21)</a>:</h4>
<p>that span isn't even available to the macro invocation <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="243549859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243549859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243549859">(Jun 22 2021 at 17:23)</a>:</h4>
<p>making that happen would be a complicated change, i'm afraid</p>



<a name="243553236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243553236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243553236">(Jun 22 2021 at 17:46)</a>:</h4>
<p>:(</p>



<a name="243553257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243553257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243553257">(Jun 22 2021 at 17:46)</a>:</h4>
<p>I was hoping that we could just tag the macro when it was picked up from the namespace.</p>



<a name="243553464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243553464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243553464">(Jun 22 2021 at 17:48)</a>:</h4>
<p>As in, <code>std::panic</code> in 2021 refers to something different than <code>std::panic</code> in 2018, and once you've referenced it, you can call it in another edition.</p>



<a name="243554064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243554064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243554064">(Jun 22 2021 at 17:52)</a>:</h4>
<p>right now it's a macro that <em>on expansion</em> expands to either <code>panic_2021!</code> or <code>panic_2015!</code>. that expansion doesn't happen in the <code>use</code> statement.</p>



<a name="243554276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243554276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243554276">(Jun 22 2021 at 17:54)</a>:</h4>
<p>Ah, I see.</p>



<a name="243554293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243554293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243554293">(Jun 22 2021 at 17:54)</a>:</h4>
<p>So we sort that out in expansion, not in name resolution.</p>



<a name="243554322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243554322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243554322">(Jun 22 2021 at 17:54)</a>:</h4>
<p>Intuitively, I would have expected it to happen in name resolution.</p>



<a name="243554354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243554354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243554354">(Jun 22 2021 at 17:54)</a>:</h4>
<p>I'm guessing fixing that would fall under "name resolution is subtle and quick to anger"?</p>



<a name="243559909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243559909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243559909">(Jun 22 2021 at 18:33)</a>:</h4>
<p>I don't know much about how name resolution works in rustc. I have an implementation of <code>type</code> statements that resolve differently depending on the edition of where you refer to it from (<a href="https://github.com/rust-lang/rust/pull/82489/files#diff-5a64b779bd650207cd0c847489075514e307eef7142419ac5f4b9184fa19e187">here</a>). But making that work for any item is hard, I've been told.</p>



<a name="243560406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/macro%20injection%20tests/near/243560406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/macro.20injection.20tests.html#243560406">(Jun 22 2021 at 18:36)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/268952-edition-2021/topic/macro.20injection.20tests/near/243553236">said</a>:</p>
<blockquote>
<p>:(</p>
</blockquote>
<p>but yeah, thatt might be another reason to not specify every single detail of how it works right now. using the <code>panic</code> token in that example would be better, but maybe not worth implementing if there's no code where it actually matters.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>